/**
 * Created by IntelliJ IDEA.
 * User: p.popov
 * Date: 28.03.13
 * Time: 13:20
 * To change this template use File | Settings | File Templates.
 */
package slicesPanels {
import flash.geom.Point;

import slicesPanels.ParametersValidator;

public class Slice9PartType {
    public static const LEFT_TOP:Slice9PartType = new Slice9PartType(new <Number>[1], new <Number>[1], new <Number>[0]);
    public static const TOP:Slice9PartType = new Slice9PartType(new <Number>[1], new <Number>[1], new <Number>[0]);
    public static const RIGHT_TOP:Slice9PartType = new Slice9PartType(new <Number>[1, -1], new <Number>[1], new <Number>[0]);
    public static const LEFT:Slice9PartType = new Slice9PartType(new <Number>[1], new <Number>[1], new <Number>[0, -90, 0]);
    public static const CENTER:Slice9PartType = new Slice9PartType(new <Number>[1], new <Number>[1], new <Number>[0]);
    public static const RIGHT:Slice9PartType = new Slice9PartType(new <Number>[-1, 1], new <Number>[1], new <Number>[0, 90, 90]);
    public static const LEFt_BOTTOM:Slice9PartType = new Slice9PartType(new <Number>[1], new <Number>[1, -1], new <Number>[0]);
    public static const BOTTOM:Slice9PartType = new Slice9PartType(new <Number>[1], new <Number>[1], new <Number>[0, 180, 0]);
    public static const RIGHT_BOTTOM:Slice9PartType = new Slice9PartType(new <Number>[1, -1], new <Number>[1, 1, -1], new <Number>[0]);

    private var scaleXModes:Vector.<Number>;
    private var scaleYModes:Vector.<Number>;
    private var rotationsInDegrees:Vector.<Number>;

    public function Slice9PartType(scaleX:Vector.<Number>, scaleY:Vector.<Number>, rotations:Vector.<Number>) {
        scaleXModes = scaleX;
        scaleYModes = scaleY;
        rotationsInDegrees = rotations;
    }


    public function getScale(resIds:Array):Point {
        var index:int = ParametersValidator.getIndexOfFirstValid(ParametersValidator.checkForNotNull, resIds);
        var result:Point = new Point();
        result.x = scaleXModes.length - 1 >= index ? scaleXModes [index] : scaleXModes[scaleXModes.length - 1];
        result.y = scaleYModes.length - 1 >= index ? scaleYModes [index] : scaleYModes[scaleYModes.length - 1];
        return result;
    }

    public function getRotation(resIds:Array):Number {
        var index:int =  ParametersValidator.getIndexOfFirstValid(ParametersValidator.checkForNotNull, resIds);
        var result:Number = rotationsInDegrees.length - 1 >= index ? rotationsInDegrees[index] : rotationsInDegrees[rotationsInDegrees.length - 1];
        return result;
    }

    public function getResourceId(resIds:Array):String {
        return ParametersValidator.getFirstValidParameter(ParametersValidator.checkForNotNull, resIds);
    }
}
}
